package com.zretc.kscxmz.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zretc.kscxmz.entity.Mail;
import com.zretc.kscxmz.entity.MailAccount;
import com.zretc.kscxmz.mappers.MailAccountMapper;
import com.zretc.kscxmz.services.MailAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class MailAccountServiceImpl implements MailAccountService {
    @Autowired
    private MailAccountMapper mapper;
    @Override
    public int add(MailAccount mailAccount) {
        return mapper.insert(mailAccount);
    }

    @Override
    public int modify(MailAccount mailAccount) {
        return mapper.update(mailAccount);
    }

    @Override
    public int remove(Integer mailAccountId) {
        return mapper.delete(mailAccountId);
    }

    @Override
    public PageInfo<MailAccount> getMailAccount(Map<String, String> map) {
        //开始分页
        PageHelper.startPage(Integer.valueOf(map.get("pageNum")),Integer.valueOf(map.get("pageSize")));
        Map<String,String> conditionMap = new HashMap<>();
        if (map.get("mailAccountName") != null){
            conditionMap.put("mailAccountName","%"+map.get("mailAccountName")+"%");
        }else{
            conditionMap.put("mailAccountName",null);
        }
        //拦截并进行分页
        List<MailAccount> mailAccounts = mapper.find(conditionMap);
        //对结果进行包装
        PageInfo<MailAccount> pageInfo = new PageInfo<>(mailAccounts);
        return pageInfo;
    }
}
